'use strict';
const Service = require('egg').Service;
class SqlService extends Service {
  async updateOrCreateExist(table, params, where) {
    const res = await this.app.mysql.select(table, {
      where: where,
    });
    if (res.length === 0) { // 不存在该记录
      return await this.app.mysql.insert(table, {...params, ...where});
    } else {
      return await this.app.mysql.update(table, params, {
        where: where,
      })
    }
  }
}
module.exports = SqlService;
